// pages/goods/exchanged_list/exchanged_list.js
var app = getApp();
Page({
  data: {
    scrollListHeight: '',//滚动列表的高度
    exchangeGoodsList: [],//兑换的商品列表
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.origin) {
      this.setData({
        message: '兑换成功',
        pageHeight: app.globalData.pageHeight - 2
      })
    } else {
      this.setData({
        pageHeight: app.globalData.pageHeight - 2
      })
    }
    this.getExchangeOptions();
  },

  getExchangeOptions: function () {
    var scrollListHeight = app.globalData.windowHeight;
    var exchangeGoodsOptions = {
      list_id: 'exchangedGoodsList',
      url: '/api/index.php?app=account&act=exchange_list',
    }
    this.setData({
      scrollListHeight: scrollListHeight,
      exchangeGoodsOptions: exchangeGoodsOptions
    })
  },

  loadMoreExchangeData: function (e) {
    let resArr = [];
    if (e.detail.data.length > 0) {
      for (let item of e.detail.data) {
        let obj = {
          goods_id: item.order_id,
          image: item.goods[0].goods_image,
          goods_name: item.goods[0].goods_name,
          price: item.goods[0].sell_price,
          status: item.status,
        }
        resArr.push(obj);
      }
    }
    // console.log(resArr);
    this.setData({
      exchangeGoodsList: resArr,
    })
  },

  /**
   * 查看商品兑换信息
   */
  viewGoods: function (e) {
    var targetId = e.detail.id;
    wx.navigateTo({
      url: '../exchanged_info/exchanged_info?order_id=' + targetId,
    })
  },

  //跳转到去做任务的列表
  linktoTask: function () {
    wx.switchTab({
      url: '../../task/mainpage/mainpage',
    })
  },
})